/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package es.midiendoelsoftware.qaMetrics.test.utils;

import es.midiendoelsoftware.qaMetrics.test.acceptance.QAMetrics;
import es.midiendoelsoftware.qaMetrics.test.beans.Metric;
import es.midiendoelsoftware.qaMetrics.test.beans.Section;
import es.midiendoelsoftware.qaMetrics.test.beans.Sumarize;
import es.midiendoelsoftware.qaMetrics.test.beans.Visualizer;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import net.sf.json.JSONObject;
import org.junit.Ignore;
import static java.text.MessageFormat.format;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
 *
 * @author carlosg
 */
public class Json2Properties {
  /*   @Ignore
    public void borrame(){
     Metric metricDate=new Metric();
         metricDate.setId("Date");
         metricDate.setValidator("jadfadf");
         metricDate.setHead(new String[]{"Fecha","Date"});
         metricDate.setBestValue("n/a");
     Metric metricNRequirements=new Metric();
         metricNRequirements.setId("nRequirements");
         metricNRequirements.setValidator("jadfadf");
         metricNRequirements.setHead(new String[]{"Nº Requisitos","Nº Requirements"});
         metricNRequirements.setBestValue("infinite");
         Metric metricNRequirementsApprovedByCustomer=new Metric();
         metricNRequirementsApprovedByCustomer.setId("nRequirementsApprovedByCustomer");
         metricNRequirementsApprovedByCustomer.setValidator("jadfadf");
         metricNRequirementsApprovedByCustomer.setHead(new String[]{"Nº Requisitos","Nº Requirements"});
         metricNRequirementsApprovedByCustomer.setBestValue("infinite");
         Section section = new Section();
         section.setId("Requirements");
         section.setTitle(new String[]{"Requisitos de usuario","User Requirements"});
         section.setDescription(new String[]{"Indica si los requesitos están claros","show if the requirements are clear"});
         section.setMetrics(new Metric[]{metricDate,metricNRequirements,metricNRequirementsApprovedByCustomer});
         section.setData(new String[][]{new String[]{"17/05/2010","3","1"},new String[]{"17/05/2010","3","2"}});
         Sumarize sumarize=new Sumarize();
         sumarize.setHead(new String[]{"Empresa"});
         sumarize.setData(new String[]{"Empresa","3","1"});
         section.setSumarize(new Sumarize[]{sumarize});
         Visualizer visualizer=new Visualizer();
         visualizer.setTitle(new String[]{"Resumen QACard","Sumarize QACard"});
         visualizer.setDescription(new String[]{"Resumen de todas las métricas","Sumarize of all metrics"});
         visualizer.setSections(new Section[]{section,section,section});
 JSONObject jsonObject = JSONObject.fromObject( visualizer );
 System.out.println( jsonObject );
    }*/
    @Test
    public void json2Properties() {
        try {
            final Visualizer metrics = QAMetrics.getMetrics("qaMetrics.json");
            final FileOutputStream fQAMetrics = new FileOutputStream("target/qaMetrics.properties");
            final OutputStreamWriter osQAMetrics = new OutputStreamWriter(fQAMetrics);
            final FileOutputStream fQAMetricsValidators = new FileOutputStream("target/qaMetricsValidators.properties");
            final OutputStreamWriter osQAMetricsValidators = new OutputStreamWriter(fQAMetricsValidators);
            //doing the tests
            for (int i = 0; i < metrics.getSections().length; i++) {
                final Section section = metrics.getSections()[i];
                osQAMetrics.write("\n##########################################################################");
                osQAMetrics.write(format("\n#Section Id:{0}", section.getId()));
                osQAMetrics.write(format("\n#        Title:{0}", section.getTitle()[0]));
                osQAMetrics.write(format("\n#        Description:{0}", section.getDescription()[0]));
                osQAMetrics.write("\n##########################################################################");
                for (int j = 0; j < section.getMetrics().length; j++) {
                    osQAMetrics.write(format("\n{0}.{1}=", section.getId(), section.getMetrics()[j].getId()));
                    osQAMetricsValidators.write(format("\n{0}.{1}={2}", section.getId(), section.getMetrics()[j].getId(),section.getMetrics()[j].getValidator()));
                }
            }
            osQAMetrics.close();
            osQAMetricsValidators.close();
            fQAMetrics.close();
            fQAMetricsValidators.close();
        } catch (IOException ioExc) {
            fail();
        }
        assertTrue(true);
    }
}
